<form action="/admin/reference/<?= $type ?>" method="post" enctype="multipart/form-data" id="reference-form">
<input type="hidden" name="reference[dummy]" value="" />
<input type="submit" value="Sačuvaj" />
<? if(isset($saved)): ?>
<div style="margin-right:5px" class="message right <?= $saved ? "ok" : "error" ?>"><?= $saved ? "Sačuvano." : "Greška pri čuvanju. Pokušajte ponovo." ?></div>
<? endif; ?>
<label>
	Dodaj sliku:<br />
	<input type="file" name="newimage" />
</label>
<ul>
<? foreach($images as $k=>$image): ?>
<li value="<?= $k ?>">
	<a class="close" href="javascript:void(0)" onclick="if(confirm('Želite da uklonite stavku?')){$(this).parent().remove()}">x</a>
	<input type="hidden" name="reference[<?= $image ?>][index]" value="<?= $k ?>" />
	<input type="hidden" name="reference[<?= $image ?>][filename]" value="<?= $image ?>" />
	<img src="/image/sta-uradismo/<?= $type ?>/<?= urlencode($image); ?>" alt="" />
</li>
<? endforeach; ?>
</ul>
</form>

<script type="text/javascript">
$("#reference-form ul").sortable({
	placeholder:'ui-sortable-placeholder',
	revert:300,
	stop: function(e,ui){
		$(e.target).children("li").each(function(index){
			$(this).attr("value",index);
			$(this).find("input[type=hidden]").eq(0).val(index);
		});
	}
});
setTimeout(function(){
	$(".message").fadeOut();
}, 2500);
</script>